import Vue from 'vue';
import Router from 'vue-router';

// 导入组件
import DatabaseConfigList from '@/components/database-config/List.vue';
import DatabaseConfigAdd from '@/components/database-config/Add.vue';
import DatabaseConfigEdit from '@/components/database-config/Edit.vue';
import SyncStrategyList from '@/components/sync-strategy/List.vue';
import SyncStrategyAdd from '@/components/sync-strategy/Add.vue';
import SyncStrategyEdit from '@/components/sync-strategy/Edit.vue';
import Home from '@/components/Home.vue';
import TableSchema from '@/components/schema/TableSchema.vue';
import DatabaseManagementList from '@/components/db-management/List.vue';
// 区域管理组件
import AreaManagementList from '@/components/area-management/List.vue';
import AreaManagementAdd from '@/components/area-management/Add.vue';
import AreaManagementEdit from '@/components/area-management/Edit.vue';
// 设备管理组件
import DeviceManagementList from '@/components/device-management/List.vue';
import DeviceManagementAdd from '@/components/device-management/Add.vue';
import DeviceManagementEdit from '@/components/device-management/Edit.vue';
// 数据同步管理组件
import ServiceManagementList from '@/components/service-management/List.vue';
import ServiceManagementAdd from '@/components/service-management/Add.vue';
import ServiceManagementEdit from '@/components/service-management/Edit.vue';
// 服务类型管理组件
import ServiceTypeManagementList from '@/components/service-type-management/List.vue';
import ServiceTypeManagementAdd from '@/components/service-type-management/Add.vue';
import ServiceTypeManagementEdit from '@/components/service-type-management/Edit.vue';
// 系统配置管理组件
import SystemConfigList from '@/components/system-config/List.vue';
// 菜单管理组件
import MenuList from '@/components/menu/List.vue';
import MenuAdd from '@/components/menu/Add.vue';
import MenuEdit from '@/components/menu/Edit.vue';

// 注册Router插件
Vue.use(Router);

// 创建路由实例
const router = new Router({
    mode: 'history',
    routes: [
        {
            path: '/',
            name: 'Home',
            component: Home,
            meta: {
                title: '首页'
            }
        },
        {
            path: '/database-config',
            name: 'DatabaseConfigList',
            component: DatabaseConfigList,
            meta: {
                title: '数据库配置管理'
            }
        },
        {
            path: '/database-config/add',
            name: 'DatabaseConfigAdd',
            component: DatabaseConfigAdd,
            meta: {
                title: '添加数据库配置'
            }
        },
        {
            path: '/database-config/edit/:id',
            name: 'DatabaseConfigEdit',
            component: DatabaseConfigEdit,
            meta: {
                title: '编辑数据库配置'
            },
            props: true
        },
        {
            path: '/sync-strategy',
            name: 'SyncStrategyList',
            component: SyncStrategyList,
            meta: {
                title: '同步策略管理'
            }
        },
        {
            path: '/sync-strategy/add',
            name: 'SyncStrategyAdd',
            component: SyncStrategyAdd,
            meta: {
                title: '添加同步策略'
            }
        },
        {
            path: '/sync-strategy/edit',
            name: 'SyncStrategyEdit',
            component: SyncStrategyEdit,
            meta: {
                title: '编辑同步策略'
            }
        },
        { 
            path: '/schema',
            name: 'TableSchema',
            component: TableSchema,
            meta: {
                title: '数据库表结构管理'
            }
        },
        {            
            path: '/db-management',
            name: 'DatabaseManagementList',
            component: DatabaseManagementList,
            meta: {
                title: '数据库管理'
            }
        },
        // 数据同步管理路由
        {            
            path: '/service-management',
            name: 'ServiceManagementList',
            component: ServiceManagementList,
            meta: {
                title: '数据同步管理'
            }
        },
        {            
            path: '/service-management/add',
            name: 'ServiceManagementAdd',
            component: ServiceManagementAdd,
            meta: {
                title: '添加服务'
            }
        },
        {            
            path: '/service-management/edit',
            name: 'ServiceManagementEdit',
            component: ServiceManagementEdit,
            meta: {
                title: '编辑服务'
            }
        },
        // 服务类型管理路由
        {            
            path: '/service-type-management',
            name: 'ServiceTypeManagementList',
            component: ServiceTypeManagementList,
            meta: {
                title: '服务类型管理'
            }
        },
        {            
            path: '/service-type-management/add',
            name: 'ServiceTypeManagementAdd',
            component: ServiceTypeManagementAdd,
            meta: {
                title: '添加服务类型'
            }
        },
        {            
            path: '/service-type-management/edit',
            name: 'ServiceTypeManagementEdit',
            component: ServiceTypeManagementEdit,
            meta: {
                title: '编辑服务类型'
            }
        },
        // 区域管理路由
        {
            path: '/area-management',
            name: 'AreaManagementList',
            component: AreaManagementList,
            meta: {
                title: '区域管理'
            }
        },
        {
            path: '/area-management/add',
            name: 'AreaManagementAdd',
            component: AreaManagementAdd,
            meta: {
                title: '添加区域'
            }
        },
        {
            path: '/area-management/edit/:id',
            name: 'AreaManagementEdit',
            component: AreaManagementEdit,
            meta: {
                title: '编辑区域'
            },
            props: true
        },
        // 设备管理路由
        {
            path: '/device-management',
            name: 'DeviceManagementList',
            component: DeviceManagementList,
            meta: {
                title: '设备管理'
            }
        },
        {
            path: '/device-management/add',
            name: 'DeviceManagementAdd',
            component: DeviceManagementAdd,
            meta: {
                title: '添加设备'
            }
        },
        {
            path: '/device-management/edit/:id',
            name: 'DeviceManagementEdit',
            component: DeviceManagementEdit,
            meta: {
                title: '编辑设备'
            },
            props: true
        },
        // 系统配置管理路由
        {
            path: '/system-config',
            name: 'SystemConfigList',
            component: SystemConfigList,
            meta: {
                title: '系统配置管理'
            }
        },
        {
            path: '/system-config/edit',
            name: 'SystemConfigEdit',
            component: () => import('../components/system-config/Edit.vue'),
            meta: {
                title: '编辑系统配置'
            }
        },

        // 菜单管理路由
        {
            path: '/menu',
            name: 'MenuList',
            component: MenuList,
            meta: {
                title: '菜单管理'
            }
        },
        {
            path: '/menu/add',
            name: 'MenuAdd',
            component: MenuAdd,
            meta: {
                title: '添加菜单'
            }
        },
        {
            path: '/menu/edit',
            name: 'MenuEdit',
            component: MenuEdit,
            meta: {
                title: '编辑菜单'
            }
        }
    ]
});

// 路由拦截器
router.beforeEach((to, from, next) => {
    // 设置页面标题
    if (to.meta.title) {
        document.title = to.meta.title + ' - DST数据同步平台';
    }
    next();
});

export default router;